home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / FlightSim / scprintf.c < prev   
Encoding:
C/C++ Source or Header  |  1996-06-22  |  2.6 KB  |  183 lines  |  [TEXT/KAHL]

  1. #include "flight.h"
  2.  
  3.  
  4. extern    GrafPtr            windManPort;
  5.  
  6.  
  7. static    long    rtrnAdrs;
  8. static    char    buffer[256];
  9.  
  10.  
  11. int        My_printf(char    *shwStr);
  12. OSErr    SendPort(char *buffer, int length);
  13.  
  14.  
  15. tprintf()
  16. {
  17.     asm    {
  18.         move.l    (sp)+,rtrnAdrs
  19.         }
  20.     sprintf(buffer);
  21.     SendPort(buffer, strlen(buffer));
  22.     asm    {
  23.         move.l    rtrnAdrs,a0
  24.         jmp        (a0)
  25.         }
  26. }
  27.  
  28. scprintf()
  29. {
  30.     asm    {
  31.         move.l    (sp)+,rtrnAdrs
  32.         }
  33.     sprintf(buffer);
  34.     My_printf(buffer);
  35.     asm    {
  36.         move.l    rtrnAdrs,a0
  37.         jmp        (a0)
  38.         }
  39. }
  40.  
  41. flprintf()
  42. {
  43.     asm    {
  44.         move.l    (sp)+,rtrnAdrs
  45.         }
  46.     sprintf(buffer);
  47. /*    AppendTempFile(buffer);*/
  48.     asm    {
  49.         move.l    rtrnAdrs,a0
  50.         jmp        (a0)
  51.         }
  52. }
  53.  
  54. static
  55. _My_printf(shwStr)
  56. char    *shwStr;
  57. {
  58.     Str255    buffer;
  59.     /*char    buffer[256];*/
  60. static    Rect    dispRect = {67, 54, 87, 166};
  61.  
  62.     ClipRect(&dispRect);
  63.     EraseRect(&dispRect);
  64.     MoveTo(dispRect.left + 10, dispRect.bottom - 4);
  65.     strcpy(buffer, shwStr);        /*    usage:    strcpy(tostring,fromstring);    */
  66.     ctop(buffer);
  67.     DrawString(buffer);
  68. }
  69.  
  70. static
  71. My_printf(shwStr)
  72. char    *shwStr;
  73. {
  74.     char    buffer[256];
  75. static    Rect    dispRect = {21, 220, 40, 510};
  76.     GrafPtr    savePort;
  77.  
  78.     GetPort(&savePort);
  79.     SetPort(windManPort);
  80.         ClipRect(&dispRect);
  81.         EraseRect(&dispRect);
  82.         MoveTo(230, 36);
  83.         strcpy(buffer, (char *)shwStr);
  84.         ctop(buffer);
  85.         DrawString(buffer);
  86.     SetPort(savePort);
  87. }
  88.  
  89. static    IOParam        portParam;
  90.  
  91. /*** open printer port ***/
  92. OpenSerPort()
  93. {
  94.     portParam.ioCompletion = 0L;
  95.     portParam.ioNamePtr = (StringPtr)("\p.BOut");
  96.     portParam.ioRefNum = 0;
  97.     portParam.ioPermssn = fsWrPerm;
  98.     portParam.ioMisc = 0L;
  99.  
  100.     PBOpen(&portParam, FALSE);
  101. /*    if (portParam.ioResult)
  102.         if (portParam.ioResult EQ -98)
  103.             GenralAlert("\PAppleTalk connected; won't be able to print");
  104.         else
  105.             GenralAlert("\PError opening printer port");
  106. */
  107. }
  108.  
  109. static
  110. OSErr
  111. SendPort(buffer, length)
  112. char    *buffer;
  113. int        length;
  114. {
  115.     portParam.ioBuffer = buffer;
  116.     portParam.ioReqCount = length;
  117.     portParam.ioPosMode = fsAtMark;
  118.  
  119.     PBWrite(&portParam, FALSE);
  120.     buffer[portParam.ioActCount] = '\0';
  121.     return(portParam.ioResult);
  122. }
  123.  
  124.  
  125. #define    KEYMAP        ((long *)0x174)
  126.  
  127. KWait()
  128. {
  129. Boolean    ShiftDown();
  130. Boolean    OptionDown();
  131.  
  132.     if (OptionDown())
  133.         return;
  134.     while(!ShiftDown());
  135.     while(ShiftDown());
  136. }
  137.  
  138. Boolean
  139. ShiftDown()
  140. {
  141.     return(KEYMAP[1] & 1);
  142. }
  143.  
  144. Boolean
  145. OptionDown()
  146. {
  147.     return(KEYMAP[1] & 4);
  148. }
  149.  
  150. Boolean
  151. CommandDown()
  152. {
  153.     return((KEYMAP[1] & 0x8000) ? TRUE:FALSE);
  154. }
  155.  
  156. Boolean
  157. CapsDown()
  158. {
  159.     return(KEYMAP[1] & 2);
  160. }
  161.  
  162. Boolean
  163. CmndPeriod()
  164. {
  165.     EventRecord     keyEvent;
  166.  
  167.     if (GetNextEvent(keyDownMask, &keyEvent))    /* ROM */
  168.         if (keyEvent.modifiers & cmdKey)
  169.             if ((keyEvent.message & charCodeMask) EQ '.')
  170.                 return(TRUE);
  171.  
  172.     return(FALSE);
  173. }
  174.  
  175. /*** has the mouse button been pressed? ***/
  176. Boolean
  177. MousePress()
  178. {
  179.     EventRecord    msEvent;
  180.  
  181.     return(GetNextEvent(mDownMask, &msEvent));
  182. }
  183.